<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;
//内容叶控制器
class ContentController extends Controller{

    public function index(){
//  	商品的信息
       $gid=Q('get.gid',0,'intval');
       $goodsModel=new \Common\Model\Goods;
	   $goodsData=$goodsModel->where('gid', $gid)->get();
//	        多说地址分配
       $dsData=$goodsModel->where('gid', $gid)->find();
	   View::with('dsData',$dsData);
//     商品的属性     
       $gtModel=new \Common\Model\Goods_attr;
       $gtData=$gtModel->where('gid', $gid)->get();
       View::with('gtData',$gtData);
//	       商品详情
	   $deModel=new \Common\Model\Goods_detail;
	   $data1=$deModel->where('gid', $gid)->find();
       $data1['big']=explode(',', $data1['big']);
	   View::with('data1',$data1);
//	      获取商品的货品表
	   $glModel=new \Common\Model\Goodslist;
       $glData=$glModel->where('gid', $gid)->get();
	   foreach($glData as $k=>$v){
				$glData[$k]['combine']=explode(',', $v['combine']);
			}
       View::with('glData',$glData);
	   $data=Db::table('goods_attr ga')->join('shop_type_attr ta','ga.taid','=','ta.taid')->where('gid', $gid)->where('class',1)->groupBy('ta.taid')->get();
	   foreach($data as $k=>$v){
		$data[$k]['sonData']=Db::table('goods_attr ga')
		->join('shop_type_attr ta','ga.taid','=','ta.taid')
		->where('ta.class',1)
		->where('gid', $gid)
		->where('ta.taid',$v['taid'])
		->get();
		}
	   View::with('data',$data);
	   View::with('goodsData',$goodsData);
	   $typeData=Db::table('shop_type_attr')->get();
	   View::with('typeData',$typeData);
//	      热卖推荐
	  $hotData=Db::table('shop_goods')->orderBy('rand()')->limit(3)->get();
      View::with('hotData',$hotData);
//	     看了又看
	  $lookData=Db::table('shop_goods')->orderBy('rand()')->limit(8)->get();
      View::with('lookData',$lookData);
//	     类型列表
      $listData=Db::table('shop_type')->get();
//	  p($listData);die;
      View::with('listData',$listData);
	  
       View::make();
    }
    public function selectsql(){
      	$combine=Q('post.combine');
		$combine=rtrim($combine,',');
//		var_dump($combine);die;

		$glModel=new \Common\Model\Goodslist;

        $glData=$glModel->where('combine',$combine)->find();
//		p($glData);die;
		if($glData['inventory'] == null){
				echo json_encode(array(
					'nm' => 0,
					'info' => '所选规格的货品库存为0，请挑选其它的颜色或尺码'
				));
		}
		if($glData['inventory'] == 0){
				echo json_encode(array(
					'nm' => 0,
					'info' => '所选规格的货品库存为0，请挑选其它的颜色或尺码'
				));
        }else{
        	echo json_encode(array(
					'nm' => 1,
					'info' =>$glData['inventory']
				));
        }

      } 
}